package com.rui.study.algorithm.T_OutOfMemoryError;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-02-25 08:37
 **/
public class VMStack {
    private static volatile int num;

    private void stackLeak() {
        num++;
        stackLeak();
    }

    private void dontStop() {
        while (true){

        }
    }

    public void stackLeakByThread() {
        while (true) {
            Thread thread = new Thread(() -> {
                System.out.println(num++);
                dontStop();
            });
            thread.start();
        }
    }

    /**
     * -Xss500m  -Xms1024m -Xmx1024m -XX:PermSize512M -XX:MaxPermSize512M
     * @param args
     */
    public static void main(String[] args) {
            VMStack stack = new VMStack();

//        try {
//            stack.stackLeak();
//        } catch (Exception e) {
//            System.out.println("栈深度：" + num);
//        }

        stack.stackLeakByThread();

    }
}
